; Program to locate a character within a string.
; The string is displayed from the character to the end.
; author:  R. Detmer     revised:  10/97

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
EXTRN strlen:NEAR32
PUBLIC _start

cr          EQU    0dh   ; carriage return character
Lf          EQU    0ah   ; linefeed character

.STACK  4096             ; reserve 4096-byte stack

.DATA
prompt1     BYTE   "String?  ", 0
prompt2     BYTE   cr, Lf, Lf, "Character?  ", 0
string      BYTE   80 DUP (?)
char        BYTE   5 DUP (?)
label1      BYTE   cr, Lf, Lf, "The rest of the string is--", 0
crlf        BYTE   cr, Lf, 0

.CODE
_start:     output prompt1        ; prompt for string
            input  string,80      ; get string
            lea    eax, string    ; find length of string
            push   eax            ; length parameter
            call   strlen
            inc    ecx            ; include null in string length
            mov    ecx, eax       ; save length of string

            output prompt2        ; prompt for character
            input  char,5         ; get character
            mov    al, char       ; character to AL

            lea    edi, string    ; offset of string
            cld                   ; forward movement
            repne scasb           ; scan while character not found
            dec    edi            ; back up to null or matching character
            
            output label1         ; print label
            output [edi]          ; output string
            output crlf           ; skip to new line

            INVOKE  ExitProcess, 0  ; exit with return code 0
            END

